Deploy Kubernetes Like a Pro: Online Setup with Kubespray 2.27.0 on Red Hat 9.5
本指南介绍如何使用 Kubespray 在多个节点上部署 Kubernetes 集群。本方案基于 Podman 运行 Kubespray 容器,并利用 Ansible 进行自动化部署,适用于希望快速搭建 Kubernetes 集群的用户。
- 查看kubespray v2.27.0 版本各个软件版本:https://github.com/kubernetes-sigs/kubespray/blob/v2.27.0/roles/kubespray-defaults/defaults/main/download.yml
1. 基础配置
1.1 设置主机名
在所有节点上执行以下命令,配置主机名:
192.168.21.170:
hostnamectl set-hostname bastion01
192.168.21.171:
hostnamectl set-hostname kube-master01
192.168.21.172:
hostnamectl set-hostname kube-node01
192.168.21.173:
hostnamectl set-hostname kube-node02
192.168.21.174:
hostnamectl set-hostname kube-node03
192.168.21.175:
hostnamectl set-hostname kube-node04
1.2 配置网络
在所有节点上编辑网络配置文件:
vim /etc/NetworkManager/system-connections/ens192.nmconnection
示例配置:
[connection]
id=ens192
uuid=f4dbd335-66ff-3056-9fcb-bbb3b4dd9543
type=ethernet
autoconnect-priority=-999
interface-name=ens192
timestamp=1736215902
[ethernet]
[ipv4]
address1=192.168.21.170/20,192.168.21.1
DNS=127.0.0.1
method=manual
[ipv6]
addr-gen-mode=eui64
method=auto
[proxy]
重启网络连接以使配置生效:
nmcli connection reload && nmcli connection down ens192 && nmcli connection up ens192
建议:完成所有节点的网络配置后,关机并创建快照,以便后续部署时能够快速恢复。
1.3 配置代理(仅在 bastion01 上)
为了加快 GitHub 及其他工具的访问速度,可以在 bastion01
配置代理:
vim /root/.bashrc
追加以下内容:
ENV_PROXY="http://192.168.21.101:7890"
enable_proxy() {
export HTTP_PROXY="$ENV_PROXY"
export HTTPS_PROXY="$ENV_PROXY"
export ALL_PROXY="$ENV_PROXY"
export NO_PROXY="localhost,127.0.0.1/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
export http_proxy="$ENV_PROXY"
export https_proxy="$ENV_PROXY"
export all_proxy="$ENV_PROXY"
export no_proxy="$NO_PROXY"
}
disable_proxy() {
unset HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY
unset http_proxy https_proxy all_proxy no_proxy
}
enable_proxy
使配置生效:
source /root/.bashrc